package me.joshua.demo4j.spring.data.jpa.first;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author <a href="mailto:daonan.zhan@gmail.com">Joshua Zhan</a>
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:context.xml")
public class Demo {

	@Autowired
	private UserRepository userRepository;

	@Test
	public void demo() {
		String name = "joshua";
		User user;
		user = userRepository.findByName(name);

		if (null == user) {
			user = new User(name);
			userRepository.save(user);
			System.out.println(user);
		} else {
			userRepository.delete(user.getId());
		}

		System.out.println(new StringBuilder().append("Current user count[")
				.append(userRepository.count()).append("]"));
	}
}
